package com.xiaomo.gitee.datamanager.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * @TableName user
 */
@TableName(value ="user")
@Data
@NoArgsConstructor
@Schema(description = "用户信息对象",name = "用户信息模型",title = "用户信息模型")
public class User implements Serializable, UserDetails {

    @TableId(value = "id",type = IdType.AUTO)
    @Schema(
            title = "id",
            description = "用户ID",
            example = "用户ID",
            format = "number",
            hidden = true
    )
    private Long id;

    @TableField("username")
    @Schema(
            title = "username",
            description = "用户名",
            example = "用户名",
            format = "string",
            requiredMode = Schema.RequiredMode.REQUIRED
    )
    private String username;

    @TableField("password")
    @Schema(
            title = "password",
            description = "密码",
            format = "string",
            requiredMode = Schema.RequiredMode.REQUIRED
    )
    private String password;

    @TableField("enable")
    @Schema(
            hidden = true
    )
    @Hidden
    private Integer enable;

    @TableField(exist = false)
    @Schema(
            hidden = true
    )
    private List<GrantedAuthority> authorities;

    @Schema(
            hidden = true
    )
    @Serial
    private static final long serialVersionUID = 1L;

    public User(String username, String password, Integer enable) {
        this.username = username;
        this.password = password;
        this.enable = enable;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return enable != 0;
    }
}